package com.glsc.ngateway.common.base.converter.platform;

import com.alibaba.excel.util.CollectionUtils;
import com.glsc.ngateway.common.api.flowable.dto.AppendixDto;
import com.glsc.ngateway.common.base.domain.mysql.gateway.platform.Appendix;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author xuchang
 */
public class AppendixConverter {

    public static AppendixDto do2Dto(Appendix config) {
        if (Objects.isNull(config)) {
            return null;
        }
        return AppendixMapper.INSTANCE.do2Dto(config);
    }

    public static List<AppendixDto> do2Dto(List<Appendix> configList) {
        return CollectionUtils.isEmpty(configList) ? java.util.Collections.emptyList() : configList.stream().map(AppendixConverter::do2Dto).collect(Collectors.toList());
    }

    public static Appendix dto2Do(AppendixDto configDto) {
        if (Objects.isNull(configDto)) {
            return null;
        }
        return AppendixMapper.INSTANCE.dto2Do(configDto);
    }

    public static List<Appendix> dto2Do(List<AppendixDto> configDtoList) {
        return CollectionUtils.isEmpty(configDtoList) ? java.util.Collections.emptyList() : configDtoList.stream().map(AppendixConverter::dto2Do).collect(Collectors.toList());
    }

    @Mapper(componentModel = "spring")
    public interface AppendixMapper {

        AppendixMapper INSTANCE = Mappers.getMapper(AppendixMapper.class);

        AppendixDto do2Dto(Appendix domain);

        List<AppendixDto> do2Dto(List<Appendix> domain);

        Appendix dto2Do(AppendixDto dto);

        List<Appendix> dto2Do(List<AppendixDto> dto);
    }
}
